/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package SteamEngineDB;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Jeff Bendixsen <jeff@westcoastcode.com>
 */
@Entity
@Table(name = "TEMPLATE_CAR")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TemplateCar.findAll", query = "SELECT t FROM TemplateCar t"),
    @NamedQuery(name = "TemplateCar.findByRunId", query = "SELECT t FROM TemplateCar t WHERE t.templateCarPK.runId = :runId"),
    @NamedQuery(name = "TemplateCar.findByCarId", query = "SELECT t FROM TemplateCar t WHERE t.templateCarPK.carId = :carId"),
    @NamedQuery(name = "TemplateCar.findByPosition", query = "SELECT t FROM TemplateCar t WHERE t.position = :position")})
public class TemplateCar implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TemplateCarPK templateCarPK;
    @Basic(optional = false)
    @Column(name = "POSITION")
    private int position;
    @JoinColumn(name = "RUN_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private TemplateRun templateRun;
    @JoinColumn(name = "CAR_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Car car;

    public TemplateCar() {
    }

    public TemplateCar(TemplateCarPK templateCarPK) {
        this.templateCarPK = templateCarPK;
    }

    public TemplateCar(TemplateCarPK templateCarPK, int position) {
        this.templateCarPK = templateCarPK;
        this.position = position;
    }

    public TemplateCar(int runId, int carId) {
        this.templateCarPK = new TemplateCarPK(runId, carId);
    }

    public TemplateCarPK getTemplateCarPK() {
        return templateCarPK;
    }

    public void setTemplateCarPK(TemplateCarPK templateCarPK) {
        this.templateCarPK = templateCarPK;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public TemplateRun getTemplateRun() {
        return templateRun;
    }

    public void setTemplateRun(TemplateRun templateRun) {
        this.templateRun = templateRun;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (templateCarPK != null ? templateCarPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TemplateCar)) {
            return false;
        }
        TemplateCar other = (TemplateCar) object;
        if ((this.templateCarPK == null && other.templateCarPK != null) || (this.templateCarPK != null && !this.templateCarPK.equals(other.templateCarPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "SteamEngineDB.TemplateCar[ templateCarPK=" + templateCarPK + " ]";
    }
    
}
